//引入接口
import API from '../../config/server'

Page({
  data:{
    hero: {},
    curUrls: []
  },
  onLoad(option)
  {
    this.getInfo(option)
  },

  //请求数据英雄详细
  getInfo(data){
    let _this = this
    wx.showLoading({
      title: '加载中...',
    })

    wx.request({
      url: API.herodetail,
      method: 'POST',
      data: data,
      dataType: 'json',
      success: (result) => {
        const info = result.data;
      
        let detailImg = info.data.heroDetail
        let imgArr = []
        for(let key in detailImg){
          if(detailImg[key].type == 'img'){
              imgArr.push(detailImg[key].text)
          }
        } 
        if(info.success){
          _this.setData({
            hero: info.data,
            curUrls: imgArr
          })
        }
        // console.log(info)
      },
      fail: (res) => {
       wx.showToast({
         title: '网络错误',
         icon: 'error',
       })
      },
      complete: (res) => {
        wx.hideLoading()
      },
    })
  },
  showHistory(){
    wx.showModal({
      title: this.data.hero.historyTitle,
      content: this.data.hero.historyContent,
      showCancel: false,
    })
  },
  showImg(e){
    let src = e.currentTarget.dataset.src
    this.imgPreview(src);
  },

  imgPreview(curImg){
    wx.previewImage({
      current: curImg, // 当前显示图片的http链接
      urls: this.data.curUrls // 需要预览的图片http链接列表
    })
  }
})